package com.hqyj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dao.ClassesMapper;
import com.hqyj.dao.DepartmentMapper;
import com.hqyj.pojo.Classes;
import com.hqyj.pojo.Department;
import com.hqyj.pojo.User;
import com.hqyj.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p></p>
 *
 * @author : zlf
 * @date : 2020-09-01 15:50
 **/
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;
    @Autowired
    ClassesMapper classesMapper;
    @Override
    public HashMap<String,Object> selectDepart(){
        HashMap<String,Object> map = new HashMap<>();
        List<Department> departmentList = departmentMapper.selecAll();
        map.put("data",departmentList);
        return map;
    }

    @Override
    public HashMap<String,Object> selectAll(Department department) {
        HashMap<String,Object> map = new HashMap<>();
        //1 设置分页参数：页码和条数
        PageHelper.startPage(department.getPage(),department.getRow());
       List<Department> departmentList = departmentMapper.selecAll();
        // 3 创建分页对象
        PageInfo<Department> pageInfo = new PageInfo<Department>(departmentList);
        List<Department> listResult = pageInfo.getList();
        for(Department e:listResult){
            System.out.println(e.toString());
        }
        map.put("total",pageInfo.getTotal());
        map.put("pages",pageInfo.getPages());
        map.put("endPage",pageInfo.getNavigateLastPage());
        map.put("curPage",department.getPage());
        map.put("data",pageInfo.getList());
        return map;
    }

    @Override
    public HashMap<String, Object> Insert(Department department) {
        HashMap<String,Object> map = new HashMap<>();
        if (departmentMapper.Insert(department)>0)
        {
            map.put("info","新增成功");
        }else {
            map.put("info","新增失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> update(Department department) {
        HashMap<String,Object> map = new HashMap<>();
        if (departmentMapper.update(department)>0)
        {
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }
}
